<template>
  <div>
    <h3 class="h3-title">动态</h3>
    <div class="eventsList">
      <!-- v-loading="eventsListLoding" :element-loading-background="ELEMENT_LOADING_BACKGROUND" element-loading-spinner="el-icon-loading"  :element-loading-text="ELEMENT_LOADING_TEXT" -->
      <div class="item" v-for="(item, index) in eventsList" :key="index">
        <div class="user-img" @click="screenUserPage(item)">
          <img :src="item.user.avatarUrl" alt="" />
        </div>
        <div class="user-info">
          <div class="title">
            <b @click="screenUserPage(item)">{{ item.user.nickname }}</b>
            <span>{{ item.type | filterType }}</span>
            <div
              v-if="$route.query.id == userInfo.profile.userId"
              class="iconfont delete"
            >
              &#xe63c;
            </div>
            <div
              v-if="$route.query.id == userInfo.profile.userId"
              @click="deleteDynamic(item)"
              class="pl"
            >
              <i class="iconfont">&#xe609;</i>
              <span>删除</span>
            </div>
          </div>
          <div class="date">
            <span>
              {{ item.eventTime | dateFilter }}
            </span>
          </div>
          <div class="info">
            {{ item.json | jsonFilter }}
          </div>
          <div class="music" v-if="isItemJsonComputed(item.json)">
            <div class="img">
              <img :src="item.json | jsonCoverFilter" alt="" />
              <i class="iconfont">&#xe638;</i>
            </div>
            <div class="details">
              <div class="title">{{ item.json | jsonNameFilter }}</div>
              <div class="auth">{{ item.json | jsonAuthFilter }}</div>
            </div>
          </div>
          <div class="pic" v-if="item.pics.length > 0">
            <!-- <el-image 
               :style="{width:'100px'}"
                :src="item.pics[0].originUrl" 
                :preview-src-list="[item.pics[0].originUrl]">
              </el-image> -->
            <img
              :width="item.pics[0].originUrl | imgWFilter"
              :src="item.pics[0].originUrl"
              alt=""
            />
          </div>
          <div class="footer-control">
            <span class="icon-span-box"
              ><i
                class="iconfont"
                :style="{
                  color: item.info.liked ? 'rgb(225,59,59)' : '#0c73c2',
                }"
                >&#xe63b;</i
              ><span class="icspan">{{
                item.info.commentThread.likedCount
              }}</span></span
            >
            <b>|</b>
            <span @click="transmitShare(item)"
              >转发 {{ item.insiteForwardCount }}</span
            >
            <b>|</b>
            <span @click="transmitDiscuss(item)"
              >评论 {{ item.info.commentThread.commentCount }}</span
            >
          </div>
        </div>
      </div>
    </div>
    <div class="more" @click="getEvent" v-if="more">加载更多</div>
    <Transmit v-if="isTransmitDialog" :isTransmitDialog.sync="isTransmitDialog" :evId="evId" @init="init" />
  </div>
</template>

<script>
import $moment from "moment";
import { apiEvent } from "@/api";
import { mapGetters } from "vuex";
import Transmit from '@/components/transmit'

export default {
  name: "EventNews",
  data() {
    return {
      lasttime:'',
      more:true,
      eventsList: [],
      evId:"",
      isTransmitDialog:false,
    };
  },
  components: {
    Transmit,
  },
  created() {
    this.init();
  },
   filters: {
    imgWFilter: function (val) {
      let img = new Image();
      img.src = val;
      let width = 190;
      if (img.height > img.width) {
        width = 190;
      } else {
        width = 224;
      }
      return width;
    },
    jsonCoverFilter: function (val) {
      try {
        return JSON.parse(val).song.img80x80;
      } catch (error) {}
    },
    jsonAuthFilter: function (val) {
      try {
        return JSON.parse(val)
          .song.artists.map((item) => item.name)
          .join("/");
      } catch (error) {}
    },
    jsonNameFilter: function (val) {
      try {
        return JSON.parse(val).song.name;
      } catch (error) {}
    },
    jsonFilter: function (val) {
      try {
        return JSON.parse(val).msg;
      } catch (error) {}
    },
    dateFilter: function (val) {
      return $moment(val).format("YYYY-MM-DD");
    },
    filterType: function (val) {
      switch (val) {
        case 18:
          return "分享单曲";
          break;
        case 19:
          return "分享专辑";
          break;
        case 17:
          return "分享电台节目";
          break;
        case 28:
          return "分享电台节目";
          break;
        case 22:
          return "转发";
          break;
        case 39:
          return "发布视频";
          break;
        case 35:
          return "分享歌单";
          break;
        case 13:
          return "分享歌单";
          break;
        case 24:
          return "分享专栏文章";
          break;
        case 41:
          return "分享视频";
          break;
        case 21:
          return "分享视频";
          break;
        default:
          return "分享单曲";
          break;
      }
    },
  },
  
  computed: {
    ...mapGetters(["singerDetails","userInfo"]),
  },
  methods: {
    init() {
      this.getEvent();
    },
    getEvent() {
      apiEvent({
        pagesize: 20,
        lasttime:this.lasttime
      }).then((data) => {
        this.eventsList = this.eventsList.concat( data.event )
        this.lasttime = data.lasttime
        this.more = data.more
      });
    },
    isItemJsonComputed(val) {
      try {
        return JSON.parse(val).song.img80x80;
      } catch (error) {}
    },
    transmitShare(val){
      this.evId =val.id
      this.isTransmitDialog = true
    },
    transmitDiscuss(val){
      console.log(val,"val");
      commentEvent({threadId:val.id}).then(data=>{
        console.log(data,"评论");
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.more{
  text-align: center;
  font-size:12px;
  color:#999;
  cursor: pointer;
}
.noList {
  flex:1;
  font-weight: 600;
  height: 359px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  span {
    margin-left: 10px;
  }
  .img {
    background-image: url(../../assets/img/myHomepagefans.png);
    background-position: no-repeat 0 9999px;
    width: 64px;
    height: 50px;
    background-position: 0 -347px;
  }
}
.item {
  &:first-child {
    padding-top: 0;
  }
  display: flex;
  padding: 20px 0;
  border-bottom: 1px solid #e8e8e9;
  .music {
    margin: 10px 0;
    padding: 0 10px;
    background-color: rgb(245, 245, 245);
    height: 60px;
    display: flex;
    align-items: center;
    .details {
      font-size: 14px;
      .title {
        color: #333;
      }
      .auth {
        color: #666;
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 450px;
      }
    }
    .img {
      margin-right: 10px;
      width: 40px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      img {
        width: 100%;
      }
      .iconfont {
        font-size: 20px;
        line-height: 1;
        color: #efefef;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }
  }
}
.h3-title {
  font-size: 24px;
  color: #333;
  border-bottom: 2px solid #c20c0c;
}

.eventsList {
  // border-right: 1px solid rgb(212, 212, 212);
  flex: 1;
  padding: 20px 0;
  border-top: 1px solid #e8e8e9;
  display: flex;
  flex-direction: column;
  // min-height: 300px;
  .footer-control {
    display: flex;
    justify-content: flex-end;
    font-size: 12px;
    .iconfont {
      display: inline-block;
      font-size: 16px;
      vertical-align: middle;
    }
    .icspan {
      vertical-align: middle;
    }
    .icon-span-box {
      transform: translateY(-2px);
    }
    & > span {
      display: inline-block;
      color: #0c73c2;
      cursor: pointer;
      &:hover {
        text-decoration: underline;
      }
    }
    b {
      color: #c7c7c7;
      margin: 0 12px;
      font-weight: 500;
    }
  }
  .user-info {
    flex: 1;
    .delete {
      float: right;
      cursor: pointer;
      font-size: 10px;
    }
    .delete:hover + div {
      display: block;
    }
    .pl {
      cursor: pointer;
      background-color: #fff;
      &:hover {
        display: block;
        background-color: rgb(243,243,243);
      }
      &::before {
        content: "";
        position: absolute;
        height: 10px;
        top: -10px;
        left: 0;
        right: 0;
      }
      display: none;
      position: absolute;
      right: 0;
      width: 105px;
      height: 30px;
      color: #666;
      border: 1px solid #cccfd9;
      box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);
      // text-align: center;
      .iconfont {
        margin-left: 4px;
        font-size: 20px;
        vertical-align: middle;
        color: rgb(201, 201, 201);
      }
      span {
        vertical-align: middle;
        margin-left: 6px;
        font-size: 12px;
      }
    }
    .info {
      width: 550px;
      overflow: hidden;
      font-size: 14px;
      color: #333;
    }
    .date {
      span {
        color: #999;
        cursor: pointer;
        font-size: 12px;
        &:hover {
          text-decoration: underline;
        }
      }
    }
    .title {
      position: relative;
      font-size: 14px;
      b {
        font-weight: 500;
        cursor: pointer;
        color: #0c73c2;
        &:hover {
          text-decoration: underline;
        }
        margin-right: 6px;
      }
      span {
        color: #666;
      }
    }
  }
  .user-img {
    cursor: pointer;
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 15px;
    img {
      width: 100%;
    }
  }
}
</style>